<?php
namespace app\common\model;

class Img extends CommonModel
{
    /**
     *
     * */
    public function S()
    {
        return $this->class;
    }
    public function test(){
        return $this->dd();
        //return '989898';
    }

    /**
     * 图片名称命名
     * 命名方式：时间+md5(时间.随机数)
     * @return string $result;
     * */
    public function imgName(){
        $time = time();
        $random = rand(100000,999999);
        //$result = date('Ymd',$time).'_'.md5($time.$random);
        $result = md5($time.$random);
        return $result;
    }
    /**
     * 组合图片物理路径
     * 如：uploads/images/20180417_5fd6bb90d5adcdfa4013a6b5c1a8273e.jpg
     * */
    public function imgThumb($path){
        return UPLOADS_IMAGES.'/'.$path;
    }

    /**
     * 组合http路径
     * 如：http:www.xxx.com/20180417_5fd6bb90d5adcdfa4013a6b5c1a8273e.jpg
     * */
    public function imgHttp($path){
        return config('img.domain').'/'.$path;
    }

    /**
     * 物理删除图片
     * @param array|string 图片路径 20180417_5fd6bb90d5adcdfa4013a6b5c1a8273e.jpg
     * */
    public function unlinkImg($path){
        if(is_array($path)){
            foreach($path as $k=>$v){
                @unlink($this->imgThumb($path));
            }
        }else{
            @unlink($this->imgThumb($path));

        }
    }
    /**
     * 批量获取图片信息
     * */
    public function info($id='',$order='',$field=''){
        if(empty($id))return false;
        $where['id'] = ['in',$id];
        $res = $this->comSelect($where,$order='',$field);
        return $res;
    }




}